<template>
  <div class="product">
    <b-row cols="1" cols-sm="1" cols-md="1" cols-lg="2">
      <b-col class="p-0 d-none d-lg-block">
        <b-row cols="2">
          <b-col
            v-for="(item, index) in list.slice(0, 4)"
            :key="index"
            class="p-0"
          >
            <div class="product_item">
              <b-img :src="staticHost + item.pic"></b-img>
              <span class="ellipsis">{{ item.name }}</span>
            </div>
          </b-col>
        </b-row>
      </b-col>

      <b-col>
        <div
          v-for="(item, index) in list.slice(0, 4)"
          :key="index"
          class="article_item"
        >
          <b-img :src="staticHost + item.pic"></b-img>
          <div class="right">
            <h5>{{ item.name }}</h5>
            <p>新华网</p>
            <span>2023-09-26</span>
          </div>
        </div>
      </b-col>
    </b-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: []
    };
  },
  computed: {
    staticHost() {
      return this.$store.state.staticHost;
    }
  },
  async fetch() {
    const { data: productData = [] } = await this.$http.$get(`api/products`, {
      searchParams: { limit: 8 }
    });

    this.list = productData.map(v => {
      const pic = v.pic;

      if (pic) {
        v.pic = pic.replace("public/", "");
      }
      return v;
    });
  }
};
</script>

<style lang="less" scoped>
.product {
  margin-top: 110px;
  .product_item {
    .size(19.86vw, 286px, width);
    position: relative;
    .size(1.875vw, 27px, margin-bottom);

    &:after {
      display: block;
      content: "";
      position: absolute;
      background: rgba(0, 0, 0, 0.4);
      left: 0;
      right: 0;
      bottom: 0;
      top: 0;
    }

    img {
      .size(19.86vw, 286px, width);
      .size(15vw, 216px, height);
    }

    span {
      position: absolute;
      bottom: 10px;
      left: 0;
      right: 0;
      color: #fff;
      z-index: 9;
      padding: 0 min(1.6vw, 24px);
      .size(1.38vw, 20x, width);
    }
    .ellipsis {
      .ellipsis(2);
    }
  }
  .article_item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #d8d8d8;
    padding: min(0.97vw, 14px) min(2.7vw, 39px) min(0.69vw, 10px) 0;
    cursor: pointer;
    &:hover {
      background: rgba(0, 0, 0, 0.1);
    }
    &:nth-child(1) {
      padding-top: 0;
    }
    img {
      width: 113px;
      height: 85px;
      margin-right: 8px;
    }
    .right {
      h5 {
        .ellipsis(1);
        font-size: 18px;
        font-weight: 500;
        color: #1d1d1f;
        margin: 0;
        padding: 0;
      }
      p {
        font-weight: 500;
        color: #9a9a9a;
        font-size: 16px;
      }
      span {
        text-align: right;
        display: block;
        color: #9a9a9a;
        font-size: 14px;
      }
    }
  }
}
</style>
